<template>
	<Row>
		<div class="box"></div>
	</Row>
	<Row>
		<Button type="primary" @click="add">测试</Button>
		<Button type="primary" @click="add2">测试2</Button>
	</Row>
</template>

<script>
import CryptoJS from 'crypto-js';
export default {
	data() {
		return {

		}
	},
	methods: {
		add() {
			console.log(`helloworld`);
			var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
			var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase");
			console.log(encrypted, decrypted);
			console.log(decrypted.toString(CryptoJS.enc.Utf8));
		},
		add2() {
			//先要转化为统一格式
			let str = CryptoJS.enc.Utf8.parse('测试');
			let base64 = CryptoJS.enc.Base64.stringify(str);
			console.log(base64);
		}
	},
	mounted() {
		var words = CryptoJS.enc.Base64.parse("admin123");
		var base_words = words.toString(CryptoJS.enc.Base64);
		console.log(base_words);
		var base64 = CryptoJS.enc.Base64.stringify(words);
		console.log(words, base64);

		let obj = {
			a: 1,
			b: 2
		}

		console.log(JSON.stringify(obj));

		//base64编码解码
		const data = '测试数据';
		//编码
		let res = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
		console.log('加密数据：', res);

		var res_decode = CryptoJS.enc.Base64.parse(res);
		let u_code = res_decode.toString(CryptoJS.enc.Utf8);

		console.log('解密数据：', u_code);
	}
}
</script>

<style lang="scss" scoped>
.box {
	width: 100px;
	height: 100px;
	border: 1px solid #000;
}
</style>